package com.ruoyi.common.config;

import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.stereotype.Component;

/**
 * 读取项目相关配置
 * 
 * @author ruoyi
 */
@Component
@ConfigurationProperties(prefix = "ruoyi")
public class RuoYiConfig
{
    /** 项目名称 */
    private String name;

    /** 上传路径 */
    private static String profile;

    /** 验证码类型 */
    private static String captchaType;
    //最大密码错误次数
    private static int maxRetryCount;
    //账号锁定分钟
    private static long lockTime;
    //密码最大未修改天数
    private static long passMaxDays;
    //密码复杂度1：6位字符 2：至少8位字母、数字、特殊字符 3：至少8位大小写字母、数字、特殊字符
    private static int passwdComplex;
    private static String patternInfo1="密码不得少于6位";
    private static String pattern1="^.{6,}$";
    private static String patternInfo2="密码必须包含密码中必须包含大小写字母、数字、特殊字符，至少8个字符";
    private static String pattern3="(?=.*[0-9])(?=.*[A-Z])(?=.*[a-z])(?=.*[^a-zA-Z0-9]).{8,}";
    private static String patternInfo3="密码必须包含密码中必须包含字母、数字、特殊字符，至少8个字符";
    private static String pattern2="(?=.*[0-9])(?=.*[a-zA-Z])(?=.*[^a-zA-Z0-9]).{8,}";

    public String getName()
    {
        return name;
    }

    public void setName(String name)
    {
        this.name = name;
    }

    public static long getPassMaxDays() {
        return passMaxDays;
    }

    public void setPassMaxDays(long passMaxDays) {
        RuoYiConfig.passMaxDays = passMaxDays;
    }

    public static int getMaxRetryCount() {
        return maxRetryCount;
    }

    public void setMaxRetryCount(int maxRetryCount) {
        RuoYiConfig.maxRetryCount = maxRetryCount;
    }

    public static long getLockTime() {
        return lockTime;
    }

    public void setLockTime(long lockTime) {
        RuoYiConfig.lockTime = lockTime;
    }

    public static String getPasswdRegex() {
        if(passwdComplex==1){
            return pattern1;
        }else if(passwdComplex==2){
            return pattern2;
        }else if(passwdComplex==3){
            return pattern3;
        }
        return null;
    }
    public static String getPasswdRegexInfo() {
        if(passwdComplex==1){
            return patternInfo1;
        }else if(passwdComplex==2){
            return patternInfo2;
        }else if(passwdComplex==3){
            return patternInfo3;
        }
        return null;
    }

    public void setPasswdComplex(int passwdComplex) {
        this.passwdComplex = passwdComplex;
    }

    public static String getProfile()
    {
        return profile;
    }

    public void setProfile(String profile)
    {
        RuoYiConfig.profile = profile;
    }

    public static String getCaptchaType() {
        return captchaType;
    }

    public void setCaptchaType(String captchaType) {
        RuoYiConfig.captchaType = captchaType;
    }

    /**
     * 获取导入上传路径
     */
    public static String getImportPath()
    {
        return getProfile() + "/import";
    }

    /**
     * 获取头像上传路径
     */
    public static String getAvatarPath()
    {
        return getProfile() + "/avatar";
    }

    /**
     * 获取下载路径
     */
    public static String getDownloadPath()
    {
        return getProfile() + "/download/";
    }

    /**
     * 获取上传路径
     */
    public static String getUploadPath()
    {
        return getProfile() + "/upload";
    }
}
